// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

import ComponentBase from "../../BASE/ComponentBase";

const {ccclass, property} = cc._decorator;

@ccclass



export class JNFU extends ComponentBase {

    // 可拖挂的图片帧属性
    @property(cc.SpriteFrame)
    FU0: cc.SpriteFrame | null = null;

    @property(cc.SpriteFrame)
   FU1: cc.SpriteFrame | null = null;

    @property(cc.SpriteFrame)
    FU2: cc.SpriteFrame | null = null;

    @property(cc.SpriteFrame)
    FU3: cc.SpriteFrame | null = null;

    @property(cc.SpriteFrame)
   FU4: cc.SpriteFrame | null = null;

    @property(cc.SpriteFrame)
    RO: cc.SpriteFrame | null = null;
    start() {
        let strings = [ "FU0","+", "FU1","/", "FU2"];
        this.setupRichText(strings);
    }

    setupRichText(strings: string[]): void {
        // 获取 RichText 组件
        let richText = this.node.getComponent(cc.RichText);
console.log(richText)
        // 构造富文本内容
        let content =
  
        
        strings.map(str => {
            // 检查字符串是否对应图片帧属性
            let imageTag = this.getImageTagForString(str);
            return imageTag ? imageTag : str;
        }).join('');
  
        // 设置富文本内容
        richText.string = content;
    }

    getImageTagForString(str: string): string | null {
        // 检查字符串是否与图片帧属性名称匹配，并返回对应的图片标签

        console.log(`<img src="Huo" width="10" height="10"/>`)
        switch (str) {
            case 'FU0':
                return this.getImgTag(this.FU0);
            case 'FU1':
                return this.getImgTag(this.FU1);
            case 'FU2':
                return this.getImgTag(this.FU2);
            case 'FU3':
                return this.getImgTag(this.FU3);
            case 'FU4':
                return this.getImgTag(this.FU4);
            case 'FU5':
                return this.getImgTag(this.RO);
            default:
                return null;
        }
    }

    getImgTag(spriteFrame: cc.SpriteFrame | null): string {
        // 如果 SpriteFrame 存在，返回富文本图片标签
        if (spriteFrame) {
            return `<img src="${spriteFrame.name}" width="140" height="140"/>`;
        }
        return '';
    }
}